/* 1668. 最大重复子字符串 */
/**
 * @param {string} sequence
 * @param {string} word
 * @return {number}
 */
var maxRepeating = function (sequence, word) {
	let ans = 0
	const n = word.length,
		m = sequence.length
	for (let c = 0; c < m; c++) {
		for (let i = c; i < m; i++) {
			if (sequence[i] === word[0]) {
				let j = i
				let num = 0
				while (j < m) {
					const temp = sequence.slice(j, j + n)
					if (temp === word) {
						num++
						j = j + n
					} else break
				}
				if (num) {
					i = j - 1
				}
				ans = Math.max(ans, num)
			}
		}
	}

	return ans
}
/* 简单枚举+动态规划 */
var maxRepeating = function (sequence, word) {
	const n = sequence.length,
		m = word.length
	if (n < m) return 0
	const f = new Array(n).fill(0)
	for (let i = m - 1; i < n; i++) {
		let valid = true
		for (let j = 0; j < m; j++) {
			if (sequence[i - m + j + 1] !== word[j]) {
				valid = false
				break
			}
		}
		if (valid) {
			f[i] = i === m - 1 ? 0 : f[i - m] + 1
		}
	}
	return Math.max.apply(null, f)
}

const res = maxRepeating('ababc', 'ab')
console.log('maxRepeating :>>', res)
